# Input
# 31
# 32 01 00 AE 90 02 00 01 02 30 03 00 AB 32 31 31 02 00 32 33 33 01 00 CC
# Output
# 32 33


# 主函数
def main():
    tag = input().strip() # get tag
    line = input().strip() # get code stream line

    hex_array = line.split(" ") # split by " "
    index = 0  # index for iter hex_array

    while index < len(hex_array):
        target = hex_array[index]
        length = int((hex_array[index + 2] + hex_array[index + 1]), 16) # joint 'index+2'(high) and 'index+1'(low), and convert to int

        if target == tag:
            # if match, extract data
            sb = []  # save target data

            # extract data from index+3 for length
            for i in range(index + 3, index + 3 + length):
                sb.append(hex_array[i])

            print(" ".join(sb).upper().strip()) # print data in uppercase joined by " "
            break  # jump out if found
        else:
            # if not match, skip current tag
            # skip num：1 Tag + 2 Length + length of Data
            index += (1 + 2 + length)

if __name__ == "__main__":
    main()